import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';

import { UtilService } from './util.service';
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable()
export class appStoreService {
  constructor(
    private http: Http,
    private utilService: UtilService
  ) { }
  // appurl='http://localhost:4397'
  appurl = 'http://appstore.arktao.com'
  LPPURL = `http://lpp.arktao.com`
  private headers = new Headers({ 'Content-Type': 'application/json' });
  GetappStoreList(): Promise<any> {
    return this.http.get(`${this.appurl}/appstore/GetappStoreList`).toPromise().then(res => {
      return res.json();
    })
  }
  AppListByGuidList(guidliststr): Promise<any> {
    return this.http.get(`${this.LPPURL}/App/AppListByGuidList?AppGuidList=${guidliststr}`).toPromise().then(res => {
      return res.json();
    })
  }
  appStoreMsg(PK_AppStoreGuid): Promise<any> {
    return this.http.get(`${this.appurl}/appstore/appStoreMsg/${PK_AppStoreGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
  App(PK_AppGuid): Promise<any> {
    return this.http.get(`${this.LPPURL}/App/App/${PK_AppGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
  GotMyApp(PK_AppGuid): Promise<any> {
    let UserGuid: string='c838af15-d7a9-424a-b096-a781aa657d1d';
    // this.utilService.getUserInfo().then(re => {
    //   if(re.status==1)UserGuid = re.userGuid
    // })
    let data = { AppGuid: PK_AppGuid, UserGuid: UserGuid }
    const url = `${this.LPPURL}/MyApp/GotMyApp`;
    return this.http.post(url, data, { headers: this.headers })
      .toPromise()
      .then(res => { return res.json() })
  }
  MyAppInfoByUser(PK_AppGuid): Promise<any> {
    let UserGuid: string='c838af15-d7a9-424a-b096-a781aa657d1d';
    // this.utilService.getUserInfo().then(re => {
    //  if(re.status==1)UserGuid = re.userGuid
    // })
    return this.http.get(`${this.LPPURL}/MyApp/MyAppInfoByUser?AppGuid=${PK_AppGuid}&UserGuid=${UserGuid}`).toPromise().then(res => {
      return res.json();
    })
  }
}